package com.example.demo.config;

import com.example.demo.common.AppVariable;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  配置拦截器
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/blog_content.html")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/blog_list.html")
                .excludePathPatterns("/search_list.html")
                .excludePathPatterns("/chack_username.html")
                .excludePathPatterns("/check_secret.html")
                .excludePathPatterns("/art/detail")
                .excludePathPatterns("/user/checkuser")
                .excludePathPatterns("/user/logout")
                .excludePathPatterns("/user/photo")
                .excludePathPatterns("/user/showuser")
                .excludePathPatterns("/art/updrcount")
                .excludePathPatterns("/art/listbypage")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/usqu/initques")
                .excludePathPatterns("/usqu/check")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/user/getcode")
                .excludePathPatterns("/dis/getdis")
                .excludePathPatterns("/dis/setdis")
                .excludePathPatterns("/art/prize");
    }

    /**
     *  静态资源映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/photo/**")
                .addResourceLocations("file:///"+ AppVariable.UPLOADS_PATH);
    }
}
